<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<ng2-toasty [position]="'top-center'"></ng2-toasty>
<section class="content">
    <div class="row">
        <!-- context start -->
        <div class="col-md-12">
            <div [ngBusy]="loading"></div>
            <div class="card">
                <div class="card-title">
                    <a class="actions__item btn btn-primary btn-sm" tooltip="Create New System Menu Type"
                       placement="bottom" (click)="startShowCreateAndUpdateModal()"><i class="zmdi zmdi-plus"></i>
                        Create New</a>
                </div>
                <div class="card-body">
                    <table class="table mb-0 mr-center">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Name</th>
                                <th>Code</th>
                                <th>Description</th>
                                <th>Active Status</th>
                                <th>Create Time</th>
                                <th>Update Time</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody *ngFor="let model of datas">
                            <tr>
                                <th scope="row">{{model.id}}</th>
                                <td>{{model.name}}</td>
                                <td>{{model.code}}</td>
                                <td>{{model.description}}</td>
                                <td class="center">
                                    <a [tooltip]="model.active ? 'current status is actived' : 'current status is not actived'">
                                        <i [ngClass]="model.active ? 'zmdi zmdi-stop' : 'zmdi zmdi-play'"></i>
                                    </a>
                                </td>
                                <td>{{model.createTime | date:'yyyy-MM-dd HH:mm:ss'}}</td>
                                <td>{{model.updateTime | date:'yyyy-MM-dd HH:mm:ss'}}</td>
                                <td>
                                    <a (click)="startShowCreateAndUpdateModal(model)"><i class="zmdi zmdi-edit"
                                                                                         tooltip="Edit this item"></i></a>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="mr-center">
                <pagination *ngIf="roles?.length && page" [(ngModel)]="currentPage" totalItems="{{page.totalElements}}"
                    maxSize="{{page.size}}"
                    (pageChanged)="pageChanged($event)" [boundaryLinks]="true">
                </pagination>
            </div>
        </div>
        <!-- context end -->
    </div>
</section>
<!-- create and update modal start -->
<div bsModal #createAndUpdateModal="bs-modal" class="modal fade" [config]="{ ignoreBackdropClick: true }">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title pull-left">
                    Create New System Menu Type
                </h5>
            </div>
            <form #createSystemRoleForm="ngForm" (ngSubmit)="createAndUpdate()">
                <div class="modal-body">
                    <div class="form-group form-group--centered">
                        <input type="text" [(ngModel)]="param.name" name="name" #name="ngModel"
                               class="form-control" required placeholder="Please enter a role name"/>
                        <p class="text-danger" *ngIf="name.errors?.rangeLength">The input character length is between
                            5-9</p>
                    </div>
                    <div class="form-group form-group--centered">
                        <input type="text" [(ngModel)]="param.description" name="description" #description="ngModel"
                               class="form-control" required placeholder="Please enter role description"/>
                        <!--[rangeLength]="[8, 20]" -->
                        <p class="text-danger" *ngIf="description.errors?.rangeLength">Passwords cannot be less than 8
                            bits,
                            and cannot be more than 20 bits</p>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-link" (click)="createAndUpdateModal.hide()">Close</button>
                    <button type="submit" class="btn btn-warning" [disabled]="!createSystemRoleForm.form.valid">Save
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- create and update modal end -->
